/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.jarpackager;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Component;
import java.awt.Frame;
import java.util.*;
import java.io.*;
import java.beans.PropertyVetoException;
import java.beans.PropertyChangeListener;
import java.util.jar.Manifest;
import java.text.MessageFormat;
import javax.swing.JFileChooser;
import javax.swing.AbstractListModel;
import javax.swing.filechooser.FileFilter;
import javax.swing.SwingUtilities;
import javax.swing.JEditorPane;
import javax.swing.text.EditorKit;
import javax.swing.event.DocumentListener;
import org.openide.explorer.ExplorerPanel;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.view.BeanTreeView;
import org.openide.TopManager;
import org.openide.DialogDescriptor;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.openide.nodes.Node;
import org.openide.cookies.ElementCookie;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.explorer.view.NodeRenderer;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileStateInvalidException;
import org.openide.windows.TopComponent;
import org.apache.regexp.RESyntaxException;
import org.netbeans.modules.jarpackager.util.ProgressListener;
import org.netbeans.modules.jarpackager.util.ProgressDialog;
import org.netbeans.modules.jarpackager.util.JarUtils;
import org.netbeans.modules.jarpackager.options.JarPackagerOption;
/** Implementation of the panel which manages jar packaging.
* Users can specify what to package, which filter to apply
* and where to store the result.
* Manifest editing is also possible.
*
* @author Dafe Simonek
*/
class PackagingPanel extends javax.swing.JPanel
implements ProgressListener, Runnable,
PropertyChangeListener {
/** Remember last browsed folder */
private static File lastChosenFolder = null;
/** Last folder where manifest was loaded from */
private static File lastManifestFolder = null;
/** Initializes the Form */
public PackagingPanel() {
initComponents ();
completeInitComps();
localize();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
targetPanel = new javax.swing.JPanel ();
jButton1 = new javax.swing.JButton ();
createJarButton = new javax.swing.JButton ();
addRepository = new javax.swing.JCheckBox ();
targetField = new javax.swing.JTextField ();
historyButton = new javax.swing.JButton ();
jTabbedPane1 = new javax.swing.JTabbedPane ();
contentPane = new javax.swing.JPanel ();
jPanel6 = new javax.swing.JPanel ();
sourcePanel = new javax.swing.JPanel ();
jPanel9 = new javax.swing.JPanel ();
addButton = new javax.swing.JButton ();
removeButton = new javax.swing.JButton ();
clearButton = new javax.swing.JButton ();
dummyPanel = new javax.swing.JPanel ();
jPanel11 = new javax.swing.JPanel ();
jScrollPane1 = new javax.swing.JScrollPane ();
chosenContent = new javax.swing.JList ();
jPanel2 = new javax.swing.JPanel ();
jPanel1 = new javax.swing.JPanel ();
commonFiltersCombo = new javax.swing.JComboBox ();
commonFilter = new javax.swing.JRadioButton ();
regExp = new javax.swing.JRadioButton ();
regExpField = new javax.swing.JTextField ();
negative = new javax.swing.JCheckBox ();
jPanel5 = new javax.swing.JPanel ();
compressed = new javax.swing.JCheckBox ();
compressionLevel = new javax.swing.JSlider ();
jLabel4 = new javax.swing.JLabel ();
manifPane = new javax.swing.JPanel ();
manifestPanel = new javax.swing.JPanel ();
jScrollPane5 = new javax.swing.JScrollPane ();
manifestPane = new javax.swing.JEditorPane ();
jPanel3 = new javax.swing.JPanel ();
generateList = new javax.swing.JCheckBox ();
jButton3 = new javax.swing.JButton ();
mainAttributes = new javax.swing.JCheckBox ();
setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8)));
targetPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints2;
jButton1.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_BrowseTip"));
jButton1.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_Browse"));
jButton1.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
browseActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 1;
gridBagConstraints2.gridy = 0;
gridBagConstraints2.gridwidth = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (0, 8, 0, 0);
targetPanel.add (jButton1, gridBagConstraints2);
createJarButton.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CreateJarTip"));
createJarButton.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CreateJar"));
createJarButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
createJarActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 1;
gridBagConstraints2.gridy = 2;
gridBagConstraints2.gridwidth = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (8, 8, 8, 0);
targetPanel.add (createJarButton, gridBagConstraints2);
addRepository.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_AddToRepositoryTip"));
addRepository.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_AddToRepository"));
addRepository.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
addRepositoryActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.gridy = 1;
gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
targetPanel.add (addRepository, gridBagConstraints2);
targetField.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_TargetFieldTip"));
targetField.addKeyListener (new java.awt.event.KeyAdapter () {
public void keyReleased (java.awt.event.KeyEvent evt) {
targetFieldKeyReleased (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.gridy = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.ipady = 4;
gridBagConstraints2.weightx = 1.0;
targetPanel.add (targetField, gridBagConstraints2);
historyButton.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_HistoryTip"));
historyButton.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_History"));
historyButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
historyButtonActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 1;
gridBagConstraints2.gridy = 1;
gridBagConstraints2.gridwidth = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (8, 8, 0, 0);
targetPanel.add (historyButton, gridBagConstraints2);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (0, 0, 8, 0);
gridBagConstraints1.weightx = 1.0;
add (targetPanel, gridBagConstraints1);
jTabbedPane1.setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(3, 0, 0, 0)));
jTabbedPane1.addChangeListener (new javax.swing.event.ChangeListener () {
public void stateChanged (javax.swing.event.ChangeEvent evt) {
jTabbedPane1StateChanged (evt);
}
}
);
contentPane.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints3;
contentPane.setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8)));
jPanel6.setLayout (new java.awt.BorderLayout ());
jPanel6.setPreferredSize (new java.awt.Dimension(250, 350));
sourcePanel.setLayout (new java.awt.BorderLayout ());
jPanel6.add (sourcePanel, java.awt.BorderLayout.CENTER);
gridBagConstraints3 = new java.awt.GridBagConstraints ();
gridBagConstraints3.gridx = 0;
gridBagConstraints3.gridy = 0;
gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.weighty = 1.0;
contentPane.add (jPanel6, gridBagConstraints3);
jPanel9.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints4;
addButton.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_AddButtonTip"));
addButton.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_AddButton"));
addButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
addButtonActionPerformed (evt);
}
}
);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.gridwidth = 0;
gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints4.insets = new java.awt.Insets (30, 8, 8, 8);
jPanel9.add (addButton, gridBagConstraints4);
removeButton.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RemoveButtonTip"));
removeButton.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RemoveButton"));
removeButton.setLabel (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RemoveButton"));
removeButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
removeButtonActionPerformed (evt);
}
}
);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.gridwidth = 0;
gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints4.insets = new java.awt.Insets (8, 8, 8, 8);
jPanel9.add (removeButton, gridBagConstraints4);
clearButton.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_ClearButtonTip"));
clearButton.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_ClearButton"));
clearButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
clearButtonActionPerformed (evt);
}
}
);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.gridwidth = 0;
gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints4.insets = new java.awt.Insets (8, 8, 8, 8);
jPanel9.add (clearButton, gridBagConstraints4);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.gridwidth = 0;
gridBagConstraints4.gridheight = 0;
gridBagConstraints4.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints4.weightx = 1.0;
gridBagConstraints4.weighty = 1.0;
jPanel9.add (dummyPanel, gridBagConstraints4);
gridBagConstraints3 = new java.awt.GridBagConstraints ();
gridBagConstraints3.gridx = 1;
gridBagConstraints3.gridy = 0;
contentPane.add (jPanel9, gridBagConstraints3);
jPanel11.setLayout (new java.awt.GridLayout (1, 1));
jPanel11.setPreferredSize (new java.awt.Dimension(250, 350));
jScrollPane1.setPreferredSize (new java.awt.Dimension(200, 250));
chosenContent.addListSelectionListener (new javax.swing.event.ListSelectionListener () {
public void valueChanged (javax.swing.event.ListSelectionEvent evt) {
chosenContentValueChanged (evt);
}
}
);
jScrollPane1.setViewportView (chosenContent);
jPanel11.add (jScrollPane1);
gridBagConstraints3 = new java.awt.GridBagConstraints ();
gridBagConstraints3.gridx = 2;
gridBagConstraints3.gridy = 0;
gridBagConstraints3.gridwidth = 0;
gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints3.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.weighty = 1.0;
contentPane.add (jPanel11, gridBagConstraints3);
jPanel2.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints5;
jPanel1.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints6;
commonFiltersCombo.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
commonFiltersComboActionPerformed (evt);
}
}
);
gridBagConstraints6 = new java.awt.GridBagConstraints ();
gridBagConstraints6.gridx = 1;
gridBagConstraints6.gridy = 0;
gridBagConstraints6.gridwidth = 0;
gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints6.insets = new java.awt.Insets (0, 0, 6, 0);
gridBagConstraints6.weightx = 1.0;
jPanel1.add (commonFiltersCombo, gridBagConstraints6);
commonFilter.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CommonFilterTip"));
commonFilter.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CommonFilter"));
commonFilter.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
commonFilterActionPerformed (evt);
}
}
);
gridBagConstraints6 = new java.awt.GridBagConstraints ();
gridBagConstraints6.gridx = 0;
gridBagConstraints6.gridy = 0;
gridBagConstraints6.insets = new java.awt.Insets (0, 0, 6, 0);
gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST;
jPanel1.add (commonFilter, gridBagConstraints6);
regExp.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RegExpTip"));
regExp.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RegExp"));
regExp.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
regExpActionPerformed (evt);
}
}
);
gridBagConstraints6 = new java.awt.GridBagConstraints ();
gridBagConstraints6.gridx = 0;
gridBagConstraints6.gridy = 1;
gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST;
jPanel1.add (regExp, gridBagConstraints6);
regExpField.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_RegExpFieldTip"));
regExpField.addKeyListener (new java.awt.event.KeyAdapter () {
public void keyReleased (java.awt.event.KeyEvent evt) {
regExpFieldKeyReleased (evt);
}
}
);
gridBagConstraints6 = new java.awt.GridBagConstraints ();
gridBagConstraints6.gridx = 1;
gridBagConstraints6.gridy = 1;
gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints6.ipady = 4;
gridBagConstraints6.weightx = 1.0;
jPanel1.add (regExpField, gridBagConstraints6);
negative.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_NegativeTip"));
negative.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_Negative"));
gridBagConstraints6 = new java.awt.GridBagConstraints ();
gridBagConstraints6.gridx = 2;
gridBagConstraints6.gridy = 1;
gridBagConstraints6.gridwidth = 0;
gridBagConstraints6.insets = new java.awt.Insets (0, 10, 0, 0);
gridBagConstraints6.anchor = java.awt.GridBagConstraints.EAST;
jPanel1.add (negative, gridBagConstraints6);
gridBagConstraints5 = new java.awt.GridBagConstraints ();
gridBagConstraints5.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints5.weightx = 1.0;
jPanel2.add (jPanel1, gridBagConstraints5);
jPanel5.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints7;
compressed.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CompressedTip"));
compressed.setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 10, 0, 0)));
compressed.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_Compressed"));
compressed.setLabel (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_Compressed"));
compressed.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
compressedActionPerformed (evt);
}
}
);
gridBagConstraints7 = new java.awt.GridBagConstraints ();
gridBagConstraints7.gridx = 0;
gridBagConstraints7.gridy = 0;
gridBagConstraints7.gridwidth = 0;
gridBagConstraints7.insets = new java.awt.Insets (0, 0, 8, 0);
gridBagConstraints7.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints7.weightx = 1.0;
jPanel5.add (compressed, gridBagConstraints7);
compressionLevel.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_CompressionLevelTip"));
compressionLevel.setPreferredSize (new java.awt.Dimension(100, 27));
compressionLevel.setValue (6);
compressionLevel.setMaximum (9);
compressionLevel.setSnapToTicks (true);
compressionLevel.setMajorTickSpacing (1);
compressionLevel.setPaintLabels (true);
compressionLevel.setName ("");
compressionLevel.addChangeListener (new javax.swing.event.ChangeListener () {
public void stateChanged (javax.swing.event.ChangeEvent evt) {
compressionLevelStateChanged (evt);
}
}
);
gridBagConstraints7 = new java.awt.GridBagConstraints ();
gridBagConstraints7.gridx = 1;
gridBagConstraints7.gridy = 1;
gridBagConstraints7.gridwidth = 0;
gridBagConstraints7.fill = java.awt.GridBagConstraints.VERTICAL;
gridBagConstraints7.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints7.weighty = 1.0;
jPanel5.add (compressionLevel, gridBagConstraints7);
jLabel4.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_Level"));
gridBagConstraints7 = new java.awt.GridBagConstraints ();
gridBagConstraints7.gridx = 0;
gridBagConstraints7.gridy = 1;
jPanel5.add (jLabel4, gridBagConstraints7);
gridBagConstraints5 = new java.awt.GridBagConstraints ();
gridBagConstraints5.gridwidth = 0;
gridBagConstraints5.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints5.insets = new java.awt.Insets (0, 8, 0, 0);
jPanel2.add (jPanel5, gridBagConstraints5);
gridBagConstraints3 = new java.awt.GridBagConstraints ();
gridBagConstraints3.gridx = 0;
gridBagConstraints3.gridy = 1;
gridBagConstraints3.gridwidth = 0;
gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints3.insets = new java.awt.Insets (8, 0, 0, 0);
gridBagConstraints3.weightx = 1.0;
contentPane.add (jPanel2, gridBagConstraints3);
jTabbedPane1.addTab ("Content", contentPane);
manifPane.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints8;
manifPane.setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8)));
manifestPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints9;
jScrollPane5.setViewportView (manifestPane);
gridBagConstraints9 = new java.awt.GridBagConstraints ();
gridBagConstraints9.gridx = 0;
gridBagConstraints9.gridy = 0;
gridBagConstraints9.gridwidth = 0;
gridBagConstraints9.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints9.insets = new java.awt.Insets (0, 0, 8, 0);
gridBagConstraints9.weightx = 1.0;
gridBagConstraints9.weighty = 1.0;
manifestPanel.add (jScrollPane5, gridBagConstraints9);
jPanel3.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints10;
generateList.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_GenerateListTip"));
generateList.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_GenerateList"));
generateList.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
generateListActionPerformed (evt);
}
}
);
gridBagConstraints10 = new java.awt.GridBagConstraints ();
gridBagConstraints10.gridx = 0;
gridBagConstraints10.gridy = 1;
gridBagConstraints10.anchor = java.awt.GridBagConstraints.WEST;
jPanel3.add (generateList, gridBagConstraints10);
jButton3.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_LoadManifestTip"));
jButton3.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_LoadManifest"));
jButton3.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
loadManifestActionPerformed (evt);
}
}
);
gridBagConstraints10 = new java.awt.GridBagConstraints ();
gridBagConstraints10.gridx = 1;
gridBagConstraints10.gridy = 0;
gridBagConstraints10.gridwidth = 0;
gridBagConstraints10.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints10.weightx = 1.0;
jPanel3.add (jButton3, gridBagConstraints10);
mainAttributes.setToolTipText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_MainAttributesTip"));
mainAttributes.setText (java.util.ResourceBundle.getBundle("org/netbeans/modules/jarpackager/Bundle").getString("CTL_MainAttributes"));
mainAttributes.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
mainAttributesActionPerformed (evt);
}
}
);
gridBagConstraints10 = new java.awt.GridBagConstraints ();
gridBagConstraints10.gridx = 0;
gridBagConstraints10.gridy = 0;
gridBagConstraints10.anchor = java.awt.GridBagConstraints.WEST;
jPanel3.add (mainAttributes, gridBagConstraints10);
gridBagConstraints9 = new java.awt.GridBagConstraints ();
gridBagConstraints9.gridx = 0;
gridBagConstraints9.gridy = 1;
gridBagConstraints9.gridwidth = 0;
gridBagConstraints9.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints9.weightx = 1.0;
manifestPanel.add (jPanel3, gridBagConstraints9);
gridBagConstraints8 = new java.awt.GridBagConstraints ();
gridBagConstraints8.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints8.weightx = 1.0;
gridBagConstraints8.weighty = 1.0;
manifPane.add (manifestPanel, gridBagConstraints8);
jTabbedPane1.addTab ("Manifest", manifPane);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 1;
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 1.0;
add (jTabbedPane1, gridBagConstraints1);
}
/** Add or remove generated main attributes of the manifest */
private void mainAttributesActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainAttributesActionPerformed
try {
if (!manifestValid) {
jarData.setManifest(new Manifest(
new ByteArrayInputStream(manifestPane.getText().getBytes())));
}
} catch (IOException exc) {
exc.printStackTrace();
// PENDING, we must notify user
return;
}
Manifest manifest = jarData.getContent().getManifest();
boolean mainAttr = mainAttributes.isSelected();
if (mainAttr) {
JarUtils.completeMainAttributes(manifest.getMainAttributes());
} else {
JarUtils.removeMainAttributes(manifest.getMainAttributes());
}
jarData.getContent().setMainAttributes(mainAttr);
fillManifestPane(manifest);
}//GEN-LAST:event_mainAttributesActionPerformed
private void jTabbedPane1StateChanged (javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
if ((manifPane != null) &&
manifPane.equals(jTabbedPane1.getSelectedComponent())) {
// manifest pane selected, refresh manifest if needed
try {
if (!manifestValid) {
jarData.setManifest(new Manifest(
new ByteArrayInputStream(manifestPane.getText().getBytes())));
}
} catch (IOException exc) {
exc.printStackTrace();
// PENDING, we must notify user
return;
}
updateManifest();
}
}//GEN-LAST:event_jTabbedPane1StateChanged
private void compressionLevelStateChanged (javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_compressionLevelStateChanged
jarData.setCompressionLevel(compressionLevel.getValue());
}//GEN-LAST:event_compressionLevelStateChanged
/** Compile current content of regular expression and signalize
* succes / failure by setting the color of the text in the field */
private void regExpFieldKeyReleased (java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regExpFieldKeyReleased
regExpField.setForeground(
REFilter.checkRegExp(regExpField.getText())
? java.awt.SystemColor.textText
: java.awt.Color.red
);
}
/** enables / disables controls according to the state of button */
private void regExpActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_regExpActionPerformed
updateFilteringControlStates();
}
/** enables / disables controls according to the state of button */
private void commonFilterActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commonFilterActionPerformed
updateFilteringControlStates();
}
/** open dialog for manipulating history */
private void historyButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historyButtonActionPerformed
if (historyDialog == null) {
HistoryPanel historyPanel = new HistoryPanel(this);
DialogDescriptor historyDesc = new DialogDescriptor (
historyPanel, // inside component
NbBundle.getBundle(PackagingPanel.class).getString("CTL_HistoryDialog"), // title
true, // modality
historyPanel // action Listener
);
historyDialog = TopManager.getDefault().createDialog(historyDesc);
}
JarUtils.centerRelativeToPV(historyDialog);
historyDialog.show();
}//GEN-LAST:event_historyButtonActionPerformed
private void compressedActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compressedActionPerformed
// update state in jar content
jarData.setCompressed(compressed.isSelected());
compressionLevel.setEnabled(compressed.isSelected());
}//GEN-LAST:event_compressedActionPerformed
private void targetFieldKeyReleased (java.awt.event.KeyEvent evt) {//GEN-FIRST:event_targetFieldKeyReleased
// Add your handling code here:
updateControlStates();
}//GEN-LAST:event_targetFieldKeyReleased
/** Selection in the chosen content list changed, update
* state of buttons */
private void chosenContentValueChanged (javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_chosenContentValueChanged
int[] selArray = chosenContent.getSelectedIndices();
removeButton.setEnabled(selArray.length > 0);
}//GEN-LAST:event_chosenContentValueChanged
private void generateListActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateListActionPerformed
try {
if (!manifestValid) {
jarData.setManifest(new Manifest(
new ByteArrayInputStream(manifestPane.getText().getBytes())));
}
} catch (IOException exc) {
exc.printStackTrace();
// PENDING, we must notify user
return;
}
if (generateList.isSelected()) {
JarUtils.generateFileList(jarData.getContent());
} else {
JarUtils.removeFileList(jarData.getContent());
}
fillManifestPane(jarData.getContent().getManifest());
jarData.setManifestFileList(generateList.isSelected());
}//GEN-LAST:event_generateListActionPerformed
private void loadManifestActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadManifestActionPerformed
JFileChooser chooser = new JFileChooser();
// show mf and txt files only by default
chooser.setFileFilter(new MfFileFilter());
if (lastManifestFolder != null) {
chooser.setCurrentDirectory(lastManifestFolder);
}
chooser.setDialogTitle(NbBundle.getBundle(PackagingPanel.class).
getString("CTL_LoadManifestTitle"));
if (chooser.showDialog(
TopManager.getDefault().getWindowManager().getMainWindow (),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_BrowseOk"))
== JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
if (f != null) {
lastManifestFolder = chooser.getCurrentDirectory();
// load the content of the file to the manifest text area
try {
manifestPane.setText(readManifestFile(f));
} catch (IOException exc) {
TopManager.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getBundle(PackagingPanel.class).
getString("MSG_LoadManifestError"),
NotifyDescriptor.ERROR_MESSAGE)
);
}
}
}
}//GEN-LAST:event_loadManifestActionPerformed
private void createJarActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createJarActionPerformed
Component comp = TopComponent.getRegistry().getActivated();
while ((comp != null) && !(comp instanceof Frame)) {
comp = comp.getParent();
}
if (comp == null) {
progressDialog = new ProgressDialog(
NbBundle.getBundle(PackagingPanel.class).
getString("CTL_ProgressDialog"), 0, 100
);
} else {
progressDialog = new ProgressDialog(
(Frame)comp,
NbBundle.getBundle(PackagingPanel.class).
getString("CTL_ProgressDialog"), 0, 100
);
}
progressDialog.setVisible(true);
createJarButton.setEnabled(canCreateJar());
// run creating process
RequestProcessor.postRequest(this);
}//GEN-LAST:event_createJarActionPerformed
/** Set the appropriate filter for the jar content. Called when
* user changes the filter.
*/
private void commonFiltersComboActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commonFiltersComboActionPerformed
Object selItem = commonFiltersCombo.getModel().getSelectedItem();
if (selItem == null)
return;
FileObjectFilter common = (FileObjectFilter)itemsToFilters.get(selItem);
jarData.setFilter(common);
}//GEN-LAST:event_commonFiltersComboActionPerformed
private void addRepositoryActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRepositoryActionPerformed
// Add your handling code here:
}//GEN-LAST:event_addRepositoryActionPerformed
/** Called when browse button pressed. Opens file chooser dialog */
private void browseActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
JFileChooser chooser = new JFileChooser();
// show jar files only
chooser.setFileFilter(new ArchivesFileFilter());
if (lastChosenFolder != null) {
chooser.setCurrentDirectory(lastChosenFolder);
}
chooser.setDialogTitle(NbBundle.getBundle(PackagingPanel.class).
getString("CTL_BrowseTitle"));
if (chooser.showDialog(
TopManager.getDefault().getWindowManager().getMainWindow (),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_BrowseOk"))
== JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
if (f != null) {
// set into text field
lastChosenFolder = chooser.getCurrentDirectory();
targetField.setText(f.getPath());
updateControlStates();
}
}
}//GEN-LAST:event_browseActionPerformed
/** Clears whole content of list representing archive content */
private void clearButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
jarData.clear();
chosenContent.clearSelection();
createJarButton.setEnabled(canCreateJar());
}//GEN-LAST:event_clearButtonActionPerformed
/** Removes currently selected nodes from the list of the root nodes
* of the archive */
private void removeButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
Object[] selVals = chosenContent.getSelectedValues();
if (selVals.length <= 0)
return;
Node[] selNodes = new Node[selVals.length];
System.arraycopy(selVals, 0, selNodes, 0, selVals.length);
jarData.removeNodes(selNodes);
chosenContent.clearSelection();
createJarButton.setEnabled(canCreateJar());
}//GEN-LAST:event_removeButtonActionPerformed
/** Adds currently selected nodes as root items to the archive */
private void addButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
if (!jarData.addNodes(sourceExplorer.getExplorerManager().
getSelectedNodes()))
TopManager.getDefault().notify(
new NotifyDescriptor.Message(
NbBundle.getBundle(PackagingPanel.class).
getString("MSG_AddNotSuccesfull"),
NotifyDescriptor.WARNING_MESSAGE
)
);
createJarButton.setEnabled(canCreateJar());
}//GEN-LAST:event_addButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel targetPanel;
private javax.swing.JButton jButton1;
private javax.swing.JButton createJarButton;
private javax.swing.JCheckBox addRepository;
private javax.swing.JTextField targetField;
private javax.swing.JButton historyButton;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JPanel contentPane;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel sourcePanel;
private javax.swing.JPanel jPanel9;
private javax.swing.JButton addButton;
private javax.swing.JButton removeButton;
private javax.swing.JButton clearButton;
private javax.swing.JPanel dummyPanel;
private javax.swing.JPanel jPanel11;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList chosenContent;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JComboBox commonFiltersCombo;
private javax.swing.JRadioButton commonFilter;
private javax.swing.JRadioButton regExp;
private javax.swing.JTextField regExpField;
private javax.swing.JCheckBox negative;
private javax.swing.JPanel jPanel5;
private javax.swing.JCheckBox compressed;
private javax.swing.JSlider compressionLevel;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel manifPane;
private javax.swing.JPanel manifestPanel;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JEditorPane manifestPane;
private javax.swing.JPanel jPanel3;
private javax.swing.JCheckBox generateList;
private javax.swing.JButton jButton3;
private javax.swing.JCheckBox mainAttributes;
// End of variables declaration//GEN-END:variables
/** The treee where to choose from */
private ExplorerPanel sourceExplorer;
/** The data model for the content of the jar */
private JarContentListModel jarData;
/** Mapping filters - items
* @associates String*/
private HashMap filtersToItems;
/** Mapping items - filters
* @associates FileObjectFilter*/
private HashMap itemsToFilters;
/** Dialog for showing progress of packaging */
private ProgressDialog progressDialog;
/** True when content type for editor is already set,
* false otherwise */
private boolean contentTypeInited;
/** cached previous files of jar content */
private List previousFiles;
/** validity of current manifest - manifest may become invalid
* after content of filter change */
private boolean manifestValid;
/** dialog for managing history of created archives.
* Accessed from HistoryPanel */
Dialog historyDialog;
/** listener to document changes in manifest pane */
private ManifestPaneL manifestPaneListener;
/** Helper operation, localizes the strings in titles of borders etc. */
private void localize () {
// target panel border
targetPanel.setBorder (new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(
new javax.swing.border.EtchedBorder(
java.awt.Color.white,
new java.awt.Color (134, 134, 134)),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_TargetPanel")),
new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 8, 5, 8))));
// source panel title
jPanel6.setBorder (new javax.swing.border.TitledBorder(
new javax.swing.border.EtchedBorder(
java.awt.Color.white,
new java.awt.Color (134, 134, 134)),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_SourcePanel")
));
// chosen content title
jPanel11.setBorder (new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(
new javax.swing.border.EtchedBorder(
java.awt.Color.white,
new java.awt.Color (134, 134, 134)),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_ChosenContent")
),
new javax.swing.border.EmptyBorder(new java.awt.Insets(3, 3, 3, 3))));
// filtering panel title
jPanel1.setBorder (new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(
new javax.swing.border.EtchedBorder(java.awt.Color.white, new java.awt.Color (134, 134, 134)),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_FilteringPanel")
),
new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 8, 7, 8))));
// compression panel title
jPanel5.setBorder (new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(
new javax.swing.border.EtchedBorder(java.awt.Color.white, new java.awt.Color (134, 134, 134)),
NbBundle.getBundle(PackagingPanel.class).getString("CTL_CompressionPanel")
),
new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 5, 4, 5))));
// tabbed pane titles (tooltips cannot be set :-(
jTabbedPane1.setTitleAt(
0,
NbBundle.getBundle(PackagingPanel.class).getString("CTL_ContentPane")
);
jTabbedPane1.setTitleAt(
1,
NbBundle.getBundle(PackagingPanel.class).getString("CTL_ManifestPane")
);
}
/** Completes the initialization of the components */
private void completeInitComps () {
// source panel
sourceExplorer = new ExplorerPanel();
ExplorerManager manager = sourceExplorer.getExplorerManager();
manager.setRootContext(
TopManager.getDefault().getPlaces().nodes().repository());
manager.addPropertyChangeListener(this);
BeanTreeView treeView = new BeanTreeView();
treeView.setPopupAllowed(false);
treeView.setRootVisible(false);
sourceExplorer.setLayout(new BorderLayout());
sourceExplorer.add(treeView, BorderLayout.CENTER);
sourceExplorer.setPreferredSize(new java.awt.Dimension(200, 250));
sourcePanel.add(sourceExplorer, BorderLayout.CENTER);
// default filters
String classesOnly =
NbBundle.getBundle(PackagingPanel.class).getString("ClassesOnly");
String def =
NbBundle.getBundle(PackagingPanel.class).getString("Default");
String all =
NbBundle.getBundle(PackagingPanel.class).getString("All");
// initialize target list data model and cell renderer
jarData = new JarContentListModel(new JarContent());
chosenContent.setModel(jarData);
chosenContent.setCellRenderer(new NodeRenderer());
// create mappings for default filters
filtersToItems = new HashMap();
filtersToItems.put(JarContent.CLASSES_ONLY, classesOnly);
filtersToItems.put(JarContent.DEFAULT, def);
filtersToItems.put(JarContent.ALL, all);
itemsToFilters = new HashMap();
itemsToFilters.put(classesOnly, JarContent.CLASSES_ONLY);
itemsToFilters.put(def, JarContent.DEFAULT);
itemsToFilters.put(all, JarContent.ALL);
commonFiltersCombo.addItem(def);
commonFiltersCombo.addItem(classesOnly);
commonFiltersCombo.addItem(all);
// group of radio buttons
javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup();
bg.add(commonFilter);
bg.add(regExp);
commonFilter.setSelected(true);
updateControlStates();
updateFilteringControlStates();
initializeFromOptions();
// attach listener to manifest pane document
manifestPane.getDocument().addDocumentListener(manifestPaneListener());
}
/** Initializes controls and initial jar content
* according to the current state of jar packager system options */
void initializeFromOptions () {
JarPackagerOption rootOption = JarPackagerOption.singleton();
// compressed
boolean curFlag = rootOption.isCompressed();
compressed.setSelected(curFlag);
compressionLevel.setEnabled(curFlag);
jarData.setCompressed(curFlag);
int level = rootOption.getCompressionLevel();
compressionLevel.setValue(level);
jarData.setCompressionLevel(level);
// manifest file list
curFlag = rootOption.isManifestFileList();
generateList.setSelected(curFlag);
jarData.setManifestFileList(curFlag);
// manifest main attributes
curFlag = rootOption.isMainAttributes();
mainAttributes.setSelected(curFlag);
jarData.getContent().setMainAttributes(curFlag);
// add to repository
addRepository.setSelected(rootOption.isAddToRepository());
}
/** Update enabled / disabled state of some controls */
void updateControlStates () {
int[] selArray = chosenContent.getSelectedIndices();
removeButton.setEnabled(selArray.length > 0);
createJarButton.setEnabled(canCreateJar());
addButton.setEnabled(JarUtils.canAdd(
jarData.getContent(),
sourceExplorer.getExplorerManager().getSelectedNodes(),
targetField.getText()
));
compressionLevel.setEnabled(compressed.isSelected());
}
/** Update enabled / disabled state of filtering controls */
void updateFilteringControlStates () {
boolean regExpEnabled = regExp.isSelected();
regExpField.setEnabled(regExpEnabled);
negative.setEnabled(regExpEnabled);
commonFiltersCombo.setEnabled(commonFilter.isSelected());
}
/** force right editor kit to be used for manifest editing */
void initContentType () {
if (!contentTypeInited) {
EditorKit kit = manifestPane.getEditorKitForContentType("text/plain"); // NOI18N
if (kit != null) {
manifestPane.getDocument().removeDocumentListener(manifestPaneListener());
String content = manifestPane.getText();
manifestPane.setContentType("text/plain"); // NOI18N
manifestPane.setEditorKit(kit);
// re-set the content again
manifestPane.setText(content);
manifestPane.getDocument().addDocumentListener(manifestPaneListener());
}
contentTypeInited = true;
}
}
boolean canCreateJar () {
// create jar should be disabled if creating is in progress...
if (progressDialog != null) {
return false;
}
String text = targetField.getText();
if (text != null)
text = text.trim();
return !"".equals(text); // NOI18N
}
/** Compute and return normalized path of target file.
* @return normalized current path of target jar file or null
* if current path cannot be obtained (target file field is empty).
* Normalizing here means adding jar extension if no extension
* was specified.
*/
String normalizedTargetPath () {
String path = targetField.getText();
if (path.trim().equals("")) { // NOI18N
return null;
}
int endMark = path.lastIndexOf("."); // NOI18N
if (endMark < 0) {
// add jar extension
path = path + "." + JarDataLoader.JAR_EXTENSION; // NOI18N
targetField.setText(path);
}
return path;
}
/** @return Current jar content which is managed by this panel */
public JarContent getJarContent () {
return jarData.getContent();
}
/** Sets given jar content to this top component. Top component
* will update its visual state according to the new jar content
* description.
* @param jc new jar content to be set.
*/
public void setJarContent (JarContent jc) {
// update list model
jarData.setContent(jc);
// generate file list flag
generateList.setSelected(jc.isManifestFileList());
// main attributes flag
mainAttributes.setSelected(jc.isMainAttributes());
// update manifest area
manifestValid = false;
previousFiles = null;
updateManifest();
// set right filter
FileObjectFilter foFilter = jc.getFilter();
String key = (String)filtersToItems.get(foFilter);
if (key != null) {
commonFilter.setSelected(true);
commonFiltersCombo.setSelectedItem(key);
} else {
// user defined filter
regExp.setSelected(true);
regExpField.setText(foFilter.toString());
if (foFilter instanceof REFilter) {
negative.setSelected(((REFilter)foFilter).isNegative());
}
}
updateFilteringControlStates();
// update target file field
File targetFile = jc.getTargetFile();
if (targetFile != null) {
targetField.setText(targetFile.getPath());
}
// update compress flag
compressed.setSelected(jc.isCompressed());
if (jc.isCompressed()) {
compressionLevel.setValue(jc.getCompressionLevel());
}
// update controls
updateControlStates();
}
/** Notification about packaging (compiling) progress.
* Update progress dialog in AWT thread */
public void progress (final int percent, final String description) {
SwingUtilities.invokeLater(new Runnable() {
public void run () {
progressDialog.setLabel(description);
progressDialog.setValue(percent);
}
});
}
/** Actually performs packaging into the jar archive */
public void run () {
File jarFile = null;
try {
String targetPath = normalizedTargetPath();
StringBuffer contentPath = new StringBuffer();
contentPath.append(
targetPath.substring(0, targetPath.lastIndexOf(".")) // NOI18N
);
contentPath.append("."); // NOI18N
contentPath.append(JarPackagerOption.singleton().getContentExt());
jarFile = new File(targetPath);
if (jarFile.exists()) {
// [PENDING] - ask if overwrite or not
jarFile.delete();
}
// set target file
jarData.setTargetFile(jarFile);
// retrieve and set manifest
refreshManifest();
jarData.setManifest(new Manifest(
new ByteArrayInputStream(manifestPane.getText().getBytes())));
// PENDING - write to the temporary file and then rename ?
ObjectOutputStream oos = null;
JarCreater creater = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(jarFile);
oos = new ObjectOutputStream(new FileOutputStream(
contentPath.toString()));
// update filter
if (regExp.isSelected()) {
REFilter filter = new REFilter(regExpField.getText());
filter.setNegative(negative.isSelected());
jarData.setFilter(filter);
}
JarContent jc = jarData.getContent();
creater = new JarCreater(jc);
creater.addProgressListener(this);
creater.createJar(fos, jarFile);
jc.writeContent(oos);
} finally {
if (fos != null)
fos.close();
if (oos != null)
oos.close();
if (creater != null)
creater.removeProgressListener(this);
// update history
JarPackagerOption.singleton().historyData().addEntry(
targetPath, contentPath.toString()
);
}
} catch (IOException exc) {
notifyCreationError(exc, "MSG_CannotCreateJar"); // NOI18N
return;
} catch (RESyntaxException exc) {
notifyCreationError(exc, "MSG_RESyntaxError"); // NOI18N
return;
} finally {
// dispose progress dialog in AWT thread
SwingUtilities.invokeLater(new Runnable() {
public void run () {
if (progressDialog.isDisplayable()) {
progressDialog.setVisible(false);
progressDialog.dispose();
progressDialog = null;
createJarButton.setEnabled(canCreateJar());
}
}
});
}
// add to repository if checked
try {
if (addRepository.isSelected()) {
JarUtils.addJarFSToRepository(jarFile, false);
}
} catch (IOException exc) {
notifyCreationError(exc, "MSG_CannotAddToRepository"); // NOI18N
} catch (PropertyVetoException exc) {
notifyCreationError(exc, "MSG_CannotAddToRepository"); // NOI18N
}
}
/** implementation of property change listener, updates state
* of buttons */
public void propertyChange (java.beans.PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
addButton.setEnabled(
JarUtils.canAdd(jarData.getContent(), (Node[])evt.getNewValue(),
targetField.getText())
);
}
}
/** Safe getter for manifest pane document listener */
DocumentListener manifestPaneListener () {
if (manifestPaneListener == null) {
manifestPaneListener = new ManifestPaneL();
}
return manifestPaneListener;
}
/** Notifies about an error during creation of the archive
* all is done in AWT thread */
private void notifyCreationError (final Exception exc,
final String resourceString) {
SwingUtilities.invokeLater(new Runnable() {
public void run () {
if (System.getProperty("netbeans.debug.exceptions") != null) {
exc.printStackTrace();
}
TopManager.getDefault().notify(
new NotifyDescriptor.Exception(
exc,
NbBundle.getBundle(PackagingPanel.class).
getString(resourceString)
)
);
}
});
}
/** Resds the content of specified etxtual file and returns
* its content as a string */
private String readManifestFile (File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
StringBuffer sb = new StringBuffer();
String curLine;
try {
while ((curLine = br.readLine()) != null) {
sb.append(curLine).append("\n"); // NOI18N
}
} finally {
br.close();
}
return sb.toString();
}
/** Fills manifest pane with the content of given manifest */
private void fillManifestPane (Manifest manifest) {
manifestPane.setText(""); // NOI18N
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
try {
manifest.write(baos);
} finally {
baos.close();
}
} catch (IOException exc) {
// mark as bad and notify user
baos = null;
TopManager.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getBundle(PackagingPanel.class).
getString("MSG_CanNotReadManifest"),
NotifyDescriptor.WARNING_MESSAGE
));
}
if (baos != null) {
manifestPane.setText(baos.toString());
// prevent from cycle
manifestValid = true;
}
}
/** Synchronizes manifest with other current state of jar content */
private void updateManifest () {
if (!manifestValid) {
JarUtils.updateManifest(/*previousFiles, */jarData.getContent());
fillManifestPane(jarData.getContent().getManifest());
previousFiles = jarData.getContent().filteredContent();
manifestValid = true;
}
}
private void refreshManifest () {
try {
if (!manifestValid) {
jarData.setManifest(new Manifest(
new ByteArrayInputStream(manifestPane.getText().getBytes())));
}
} catch (IOException exc) {
exc.printStackTrace();
// PENDING, we must notify user
return;
}
updateManifest();
}
/** Implementation of TxtFileFilter interface which accepts mf
* and txt files. */
static final class MfFileFilter extends FileFilter {
/** Accepts only directories and archives */
public boolean accept (File f) {
return f.isDirectory() || f.getName().endsWith(".mf") || // NOI18N
f.getName().endsWith(".txt") || // NOI18N
f.getName().endsWith(".MF"); // NOI18N
}
/** Returns a description of this filter */
public String getDescription () {
return NbBundle.getBundle(PackagingPanel.class).
getString("CTL_MfFiles");
}
} // end of TxtFileFilter inner class
/** Implementation of FileFilter interface which accepts archives. */
static final class ArchivesFileFilter extends FileFilter {
/** Accepts only directories and archives */
public boolean accept (File f) {
return f.isDirectory() || f.getName().endsWith(".jar") || // NOI18N
f.getName().endsWith(".zip"); // NOI18N
}
/** Returns a description of this filter */
public String getDescription () {
return NbBundle.getBundle(PackagingPanel.class).
getString("CTL_JarArchivesMask");
}
} // end of ArchivesFileFilter inner class
/** The data model for the list showing chosen content of
* the jar archive. Delegates the work of enumerating
* the jar content to the composited JarCreater instance.
*/
final class JarContentListModel extends AbstractListModel {
/** Ascoiated jar content, we delegate the work to it */
JarContent jc;
/** List holding current nodes */
List nodes;
/** List holding current list of file objects representing
* full content which will appear in resulting archive */
List fullContent;
/** State of the model - full content or nodes only */
boolean full;
/** Creates the model with asociated jar creater */
JarContentListModel (JarContent jc) {
this.jc = jc;
nodes = new ArrayList(10);
fullContent = new ArrayList();
setFull(false);
}
/** Returns the value at the specified index. */
public Object getElementAt (int index) {
return full ? fullContent.get(index) : nodes.get(index);
}
/** Returns the length of the list. */
public int getSize () {
return full ? fullContent.size() : nodes.size();
}
/** Adds specified array of nodes to the model */
boolean addNodes (Node[] nodeArray) {
boolean allAdded = JarUtils.canAdd(jc, nodeArray, targetField.getText());
JarUtils.addFileList(jc, nodeArray);
setContent(jc);
return allAdded;
}
/** Removes specified array of nodes from the model */
boolean removeNodes (Node[] nodeArray) {
JarUtils.removeFileList(jc, nodeArray);
setContent(jc);
return true;
}
/** Clears all data in the model */
void clear () {
int prevSize = full ? fullContent.size() : nodes.size();
nodes.clear();
jc.clear();
if (full)
updateFull();
fireContentsChanged(this, 0, Math.max(prevSize - 1, 0));
}
/** Sets the model to the state when full archive content
* is shown or only rrot nodes are shown */
void setFull (boolean full) {
if (this.full == full)
return;
int prevSize = full ? fullContent.size() : nodes.size();
this.full = full;
if (full)
updateFull();
fireContentsChanged(this, 0, Math.max(prevSize - 1, 0));
}
void setFilter (FileObjectFilter filter) {
jc.setFilter(filter);
}
void setManifest (Manifest manifest) {
jc.setManifest(manifest);
}
void setManifestFileList (boolean manifestFileList) {
jc.setManifestFileList(manifestFileList);
}
void setTargetFile (File targetFile) {
jc.setTargetFile(targetFile);
}
void setCompressed (boolean compressed) {
jc.setCompressed(compressed);
}
void setCompressionLevel (int level) {
jc.setCompressionLevel(level);
}
/** Returns jar content */
JarContent getContent () {
return jc;
}
void setContent (JarContent jc) {
int prevSize = full ? fullContent.size() : nodes.size();
this.jc = jc;
// update nodes array
FileObject[] fos = (FileObject[])jc.getContent().
toArray(new FileObject[0]);
nodes = new ArrayList(fos.length);
DataObject curDO = null;
Node curNode = null;
boolean missingDOs = false;
String displayName = null;
for (int i = 0; i < fos.length; i++) {
try {
curDO = DataObject.find(fos[i]);
} catch (DataObjectNotFoundException exc) {
// mark the failure and skip this file object
missingDOs = true;
continue;
}
curNode = curDO.getNodeDelegate();
if (!nodes.contains(curNode)) {
// complete the name if root of FS
if ((fos[i].isRoot()) && ("".equals(curNode.getDisplayName()))) { // NOI18N
try {
curNode.setDisplayName(fos[i].getFileSystem().getDisplayName());
// System.out.println("Setting: " + fos[i].getFileSystem().getDisplayName()); // NOI18N
} catch (FileStateInvalidException exc) {
// defunct file system, ignore it....
}
}
nodes.add(curNode);
}
}
if (full)
updateFull();
manifestValid = false;
fireContentsChanged(this, 0, Math.max(prevSize - 1, nodes.size()));
// notify if some nodes could not be created from
// jar content's file objects
if (missingDOs) {
TopManager.getDefault().notify(
new NotifyDescriptor.Message(
NbBundle.getBundle(PackagingPanel.class).
getString("MSG_NodesMissing"),
NotifyDescriptor.WARNING_MESSAGE
)
);
}
}
/** Updates the full content data */
private void updateFull () {
fullContent = jc.filteredContent();
}
}; // end of JarContentListModel inner class
private final class ManifestPaneL implements DocumentListener {
public void changedUpdate(javax.swing.event.DocumentEvent p1) {
}
public void removeUpdate(javax.swing.event.DocumentEvent p1) {
manifestValid = false;
}
public void insertUpdate(javax.swing.event.DocumentEvent p1) {
manifestValid = false;
}
}
}
/*
* <<Log>>
*/